ActiveAdmin.register System do

  actions :all, :except => [:new, :edit, :destroy]
  menu :label => "Scanning results", :priority => 1, :parent => "Scan"

  config.clear_sidebar_sections!

  index do

    column t("systems.form.network_name"), :domain
    column t("systems.form.ip_address"), :ip
    column(t("systems.form.status")){|system|
      if system.status == '-1'
        status = 'Running'
      elsif system.status == '3'
        status = 'Finished'
      else
        status = 'Unknow'
      end

      status_tag(status)
    }
    column t("systems.form.files_done"), :filesdone
    column t("results.form.total_files"), :filestotal
    column t("results.form.bytes_done"), :bytesdone
    column t("results.form.total_bytes"), :bytestotal
    column t("systems.form.database_done"), :dbdone
    column t("systems.form.total_database"), :dbtotal
    column(t("systems.form.updated")){|system|
      now = Time.now
      last_update = system.updated_at

      time = now - last_update
      updated = (time.to_i / 60)

      if updated >= 60
        if updated >= 60 and updated < 120 
          last_update = (updated.to_i / 60).to_s + " hour ago"
        elsif updated >= 1440
          last_update = (updated.to_i / 1440).to_s + " days ago"
        else
          last_update = (updated.to_i / 60).to_s + " hours ago"
        end
      else
        last_update = updated.to_i.to_s + " minutes ago"
      end

      last_update
    }
    column t("systems.form.tracker"), :tracker

    default_actions
  end
end
